﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace C7
{
	/// <summary>
	/// Interaction logic for ModuleTab.xaml
	/// </summary>
	public partial class ModuleTab : UserControl
	{
		public ModuleTab()
		{
			this.InitializeComponent();
        }

        #region BackgroundColorProperty
        public Brush BackgroundColor
        {
            get { return (Brush)GetValue(BackgroundColorProperty); }
            set { SetValue(BackgroundColorProperty, value); }
        }

        public static readonly DependencyProperty BackgroundColorProperty =
                                                DependencyProperty.Register(
                                                                            "BackgroundColor",
                                                                            typeof(Brush),
                                                                            typeof(ModuleTab),
                                                                            new FrameworkPropertyMetadata(
                                                                            new PropertyChangedCallback(ChangeBackgroundColor)));

        private static void ChangeBackgroundColor (DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            (source as ModuleTab).UpdateBackgroundColor((e.NewValue as Brush));
        }

        private void UpdateBackgroundColor(Brush newBackgroundColor)
        {
            rectBackground.Fill = newBackgroundColor;
        } 
        #endregion

        #region TitleTextProperty
        public string TitleText
        {
            get { return (string)GetValue(TitleTextProperty); }
            set { SetValue(TitleTextProperty, value); }
        }

        public static readonly DependencyProperty TitleTextProperty =
                                                DependencyProperty.Register(
                                                                            "TitleText",
                                                                            typeof(string),
                                                                            typeof(ModuleTab),
                                                                            new FrameworkPropertyMetadata(
                                                                            new PropertyChangedCallback(ChangeTitleText)));

        private static void ChangeTitleText(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            (source as ModuleTab).UpdateTitleText((e.NewValue as string));
        }

        private void UpdateTitleText(string newTitleText)
        {
            tbTitle.Text = newTitleText;
        }
        #endregion

        #region DescriptionTextProperty
        public string DescriptionText
        {
            get { return (string)GetValue(DescriptionTextProperty); }
            set { SetValue(DescriptionTextProperty, value); }
        }

        public static readonly DependencyProperty DescriptionTextProperty =
                                                DependencyProperty.Register(
                                                                            "DescriptionText",
                                                                            typeof(string),
                                                                            typeof(ModuleTab),
                                                                            new FrameworkPropertyMetadata(
                                                                            new PropertyChangedCallback(ChangeDescriptionText)));

        private static void ChangeDescriptionText(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            (source as ModuleTab).UpdateDescriptionText((e.NewValue as string));
        }

        private void UpdateDescriptionText(string NewDescriptionText)
        {
            tbDescription.Text = NewDescriptionText;
        }
        #endregion

        #region MainImageProperty
        public ImageSource MainImage
        {
            get { return (ImageSource)GetValue(MainImageProperty); }
            set { SetValue(MainImageProperty, value); }
        }

        public static readonly DependencyProperty MainImageProperty =
                                                DependencyProperty.Register(
                                                                            "MainImage",
                                                                            typeof(ImageSource),
                                                                            typeof(ModuleTab),
                                                                            new FrameworkPropertyMetadata(
                                                                            new PropertyChangedCallback(ChangeMainImage)));

        private static void ChangeMainImage(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            (source as ModuleTab).UpdateMainImage((e.NewValue as ImageSource));
        }

        private void UpdateMainImage(ImageSource newMainImage)
        {
            imgMainImage.Source = newMainImage;
        }
        #endregion

        #region UperSecondaryImageProperty
        public ImageSource UperSecondaryImage
        {
            get { return (ImageSource)GetValue(UperSecondaryImageProperty); }
            set { SetValue(UperSecondaryImageProperty, value); }
        }

        public static readonly DependencyProperty UperSecondaryImageProperty =
                                                DependencyProperty.Register(
                                                                            "UperSecondaryImage",
                                                                            typeof(ImageSource),
                                                                            typeof(ModuleTab),
                                                                            new FrameworkPropertyMetadata(
                                                                            new PropertyChangedCallback(ChangeUperSecondaryImage)));

        private static void ChangeUperSecondaryImage(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            (source as ModuleTab).UpdateUperSecondaryImage((e.NewValue as ImageSource));
        }

        private void UpdateUperSecondaryImage(ImageSource newUperSecondaryImage)
        {
            imgUperSecondaryImage.Source = newUperSecondaryImage;
        }
        #endregion

        #region LowerSecondaryImageProperty
        public ImageSource LowerSecondaryImage
        {
            get { return (ImageSource)GetValue(LowerSecondaryImageProperty); }
            set { SetValue(LowerSecondaryImageProperty, value); }
        }

        public static readonly DependencyProperty LowerSecondaryImageProperty =
                                                DependencyProperty.Register(
                                                                            "LowerSecondaryImage",
                                                                            typeof(ImageSource),
                                                                            typeof(ModuleTab),
                                                                            new FrameworkPropertyMetadata(
                                                                            new PropertyChangedCallback(ChangeLowerSecondaryImage)));

        private static void ChangeLowerSecondaryImage(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            (source as ModuleTab).UpdateLowerSecondaryImage((e.NewValue as ImageSource));
        }

        private void UpdateLowerSecondaryImage(ImageSource newLowerSecondaryImage)
        {
            imgLowerSecondaryImage.Source = newLowerSecondaryImage;
        }


        #endregion

        private void ViewBoxLoaded(object sender, System.Windows.RoutedEventArgs e)
        {
            viewbox.Height = LayoutRoot.ActualHeight + 24;
            viewbox.Width = LayoutRoot.ActualWidth + 24;
        }

        private void ModuleLoaded(object sender, System.Windows.RoutedEventArgs e)
        {
            if (tbTitle.Text == "Personalization")
        	{
        	    tbZation.Visibility = Visibility.Visible; 
        	}
                
        }
	}
}